/*
package com.alipay.app.groupmeal.standard.util;

import android.util.Log;
import com.serialport.SerialPort;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class SerialCommunication {

    private static final String TAG = "SerialCommunication";
    private SerialPort serialPort;
    private final File device = new File("/dev/ttyS0"); // 替换为你的串口设备
    private final int baudrate = 9600; // 波特率

    public void start() {
        try {
            serialPort = new SerialPort(device, baudrate);
            final InputStream inputStream = serialPort.getInputStream();
            final OutputStream outputStream = serialPort.getOutputStream();

            // 创建一个接收线程
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    byte[] buffer = new byte[1024];
                    int bytesRead;
                    while (true) {
                        try {
                            bytesRead = inputStream.read(buffer);
                            if (bytesRead > 0) {
                                // 对接收到的数据进行处理
                                byte[] receivedBytes = new byte[bytesRead];
                                System.arraycopy(buffer, 0, receivedBytes, 0, bytesRead);
                                // 转换为十六进制字符串
                                String hexString = bytesToHex(receivedBytes);
                                Log.d(TAG, "Received HEX: " + hexString);
                            }
                        } catch (IOException e) {
                            Log.e(TAG, "Error reading from input stream", e);
                            break;
                        }
                    }
                }
            });
            thread.start();

            // 示例：发送十六进制命令
            String hexCommand = "01 03 00 00 00 01 84 0A"; // 示例命令，用空格分隔
            byte[] commandBytes = hexStringToBytes(hexCommand);
            outputStream.write(commandBytes);

        } catch (IOException e) {
            Log.e(TAG, "Error opening serial port", e);
        }
    }

    public void stop() {
        if (serialPort != null) {
            serialPort.close();
        }
    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : bytes) {
            String hex = Integer.toHexString(0xFF & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
            hexString.append(' ');
        }
        return hexString.toString();
    }

    private static byte[] hexStringToBytes(String hexString) {
        if (hexString == null || hexString.equals("")) {
            return null;
        }
        hexString = hexString.replaceAll(" ", "");
        int len = hexString.length();
        byte[] bytes = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
                    + Character.digit(hexString.charAt(i + 1), 16));
        }
        return bytes;
    }
}
*/
